const User = require('./user');
const Recipe = require('./recipe');
const DietRecord = require('./dietRecord');
const SportRecord = require('./sportRecord');
const Food = require('./food');
const WeightRecord = require('./weightRecord');
const SleepRecord = require('./sleepRecord');
const Post = require('./post');

// 用户和食谱的关联
User.hasMany(Recipe, {
  foreignKey: 'createdBy',
  as: 'recipes'
});
Recipe.belongsTo(User, {
  foreignKey: 'createdBy',
  as: 'creator'
});

// 用户和饮食记录的关联
User.hasMany(DietRecord, {
  foreignKey: 'userId',
  as: 'dietRecords'
});
DietRecord.belongsTo(User, {
  foreignKey: 'userId',
  as: 'user'
});

// 用户和运动记录的关联
User.hasMany(SportRecord, {
  foreignKey: 'userId',
  as: 'sportRecords'
});
SportRecord.belongsTo(User, {
  foreignKey: 'userId',
  as: 'user'
});

// 用户和体重记录的关联
User.hasMany(WeightRecord, {
  foreignKey: 'userId',
  as: 'weightRecords'
});
WeightRecord.belongsTo(User, {
  foreignKey: 'userId',
  as: 'user'
});

// 用户和睡眠记录的关联
User.hasMany(SleepRecord, {
  foreignKey: 'userId',
  as: 'sleepRecords'
});
SleepRecord.belongsTo(User, {
  foreignKey: 'userId',
  as: 'user'
});

// 用户和社区帖子的关联
User.hasMany(Post, {
  foreignKey: 'userId',
  as: 'posts'
});
Post.belongsTo(User, {
  foreignKey: 'userId',
  as: 'user'
});

// 帖子和食谱的关联
Post.hasOne(Recipe, {
  foreignKey: 'postId',
  as: 'recipe'
});
Recipe.belongsTo(Post, {
  foreignKey: 'postId',
  as: 'post'
});

module.exports = {
  User,
  Recipe,
  DietRecord,
  SportRecord,
  Food,
  WeightRecord,
  SleepRecord,
  Post
}; 